package game.view.loading
{
	import game.manager.LayerManager;
	import game.define.NotificationNames;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	import utiles.StageProxy;
	
	/**
	 * 提示当前正在加载情况
	 * @author jjww
	 * 
	 */	
	public class LoadingMediator extends Mediator
	{
		public static const NAME:String = "LoadingMediator";
		
		public function LoadingMediator(mediatorName:String=null, viewComponent:Object=null)
		{
			super(NAME, new LoadingView());
		}
		
		private function get view():LoadingView
		{
			return viewComponent as LoadingView;
		}
		
		override public function listNotificationInterests():Array
		{
			return [
				NotificationNames.SHOW_LOADING_VIEW,
				NotificationNames.HIDE_LOADING_VIEW,
				NotificationNames.UPDATE_LOADER_INFO
			];
		}
		
		override public function handleNotification(notification:INotification):void
		{
			switch (notification.getName())
			{
				case NotificationNames.SHOW_LOADING_VIEW:
					showLoadingView();
					break;
				case NotificationNames.HIDE_LOADING_VIEW:
					hideLoadingView();
					break;
				case NotificationNames.UPDATE_LOADER_INFO:
					updateLoaderInfo(notification.getBody() as String);
					break;
			}
		}
		
		////////////////////////////////////////////////////////////////////////////
		
		private function updateLoaderInfo(prompt:String):void
		{
			view.txtPrompt.text = prompt;
		}
		
		private function showLoadingView():void
		{
			if (!LayerManager.loadingLayer.contains(view))
				LayerManager.loadingLayer.addChild(view);
		}
		
		private function hideLoadingView():void
		{
			if (LayerManager.loadingLayer.contains(view))
				LayerManager.loadingLayer.removeChild(view);
		}
	}
}